opendir
打開目錄句柄
opendir()
函數打開目錄句柄。
打開一個目錄,讀取它的內容,然後關閉:
<?php $dir = "/images/" ; // 打開目錄,然後讀取其內容 if ( is_dir ( $dir ) ) { if ( $dh = opendir ( $dir ) ) { while ( ( $file = readdir ( $dh ) ) !== false ) { echo "filename:" . $file . "<br>" ; } closedir ( $dh ) ; } } ?>
結果:
filename: cat.gif filename: dog.gif filename: horse.gif
opendir ( path , context ) ;
參數 | 描述 |
---|---|
path | 必需。規定要打開的目錄路徑。 |
context | 可選。規定目錄句柄的環境。 context是可修改目錄流的行為的一套選項。 |